/**
 * 获胜队伍结算通用回调函数 简化获胜队伍结算流程代码
 * @param {*} fight_data 
 * @param {*} win_team_index 
 * @param {*} fail_team_index 
 * @param {*} calback_fn 
 */
export function win_team_settlement_callback(fight_data, win_team_index, fail_team_index, calback_fn) {
    let win_team = fight_data["队伍数据"][win_team_index];
    for (let index = 0; index < win_team.length; index++) {
        if (win_team[index] && win_team[index]["类型"] === "角色" && _CharactersData.has(win_team[index]["id"])) {
            let characters_id = win_team[index]["id"];
            let characters = _CharactersData.get(characters_id);
            calback_fn(characters_id, characters);
        }
    }
}
/**
 * 失败队伍结算通用回调函数 简化失败队伍结算流程代码
 * @param {*} fight_data 
 * @param {*} win_team_index 
 * @param {*} fail_team_index 
 * @param {*} calback_fn 
 */
export function fail_team_settlement_callback(fight_data, win_team_index, fail_team_index, calback_fn) {
    let fail_team = fight_data["队伍数据"][fail_team_index];
    for (let index = 0; index < fail_team.length; index++) {
        if (fail_team[index] && fail_team[index]["类型"] === "角色" && _CharactersData.has(fail_team[index]["id"])) {
            let characters_id = fail_team[index]["id"];
            let characters = _CharactersData.get(characters_id);
            calback_fn(characters_id, characters);
        }
    }
}

/**
 * 战斗结算
 * @param {*} fight_data 战斗数据
 * @param {*} win_team_index 获胜队伍
 * @returns 
 */
export function settlement(fight_data, win_team_index) {
    let fight_type = fight_data["战斗类型"];
    console.debug(`开始战斗结算 [${fight_type}]`);
    // 结算
    let settlement_data = _FightSettlementData.get(`${fight_type}`);
    if (settlement_data) {
        let fail_team_index = win_team_index === 0 ? 1 : 0;
        if (settlement_data["胜利队伍"] !== undefined) {
            console.debug(`胜利队伍结算 [${win_team_index}] [${fight_type}]`);
            settlement_data["胜利队伍"](fight_data, win_team_index, fail_team_index);
        }
        if (settlement_data["失败队伍"] !== undefined) {
            console.debug(`失败队伍结算 [${win_team_index}] [${fight_type}]`);
            settlement_data["失败队伍"](fight_data, win_team_index, fail_team_index);
        }
        console.debug("完成战斗结算");
    } else {
        console.warn(`未配置结算奖励 [${fight_type}]`);
    }
}
